home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
hity wydania
/
trueSpace 7.6
/
tS761B8Std.exe
/
{app}
/
Scripts
/
D3D
/
RsD3DMaterialFromME_Template.fx
< prev
next >
Wrap
Text File
|
2008-06-10
|
8KB
|
236 lines
#line 3 "MainD3DShaderTemplate"
//----------------------------------------------------------------------
//END - The custom shader code
//----------------------------------------------------------------------
uniform float RsD3DMaterialFromME_fNormalMod = 1.0f;
D3_VERTEXOUTPUT RsD3DMaterialFromME_VertexShader(in RtFloat4 D3_pInputPosition : POSITION,
in RtFloat3 D3_vInputNormal : NORMAL,
in RtFloat3 D3_vInputTangent : TANGENT,
in float2 D3_vInputTexCoords1 : TEXCOORD0,
in float2 D3_vInputTexCoords2: TEXCOORD1,
in RtFloat4 D3_cInputColor : COLOR0)
{
D3_VERTEXOUTPUT Output;
Output.D3_pClipPosition = mul(D3_pInputPosition , D3_mObjectToClip);
Output.D3_vVertexTexCoords.xy = D3_vInputTexCoords1.xy;
Output.D3_vVertexTexCoords.wz = D3_vInputTexCoords2.xy;
Output.D3_pVertexPosition = mul(D3_pInputPosition, D3_mObjectToWorld);
float3 vEye = D3_pEye - Output.D3_pVertexPosition;
Output.D3_vEye.xyz = normalize(vEye);
Output.D3_vEye.w = length(vEye);
//Flip the normal and tangent direction if we are processing the backface here
float3 vInputNormal = RsD3DMaterialFromME_fNormalMod * D3_vInputNormal;
float3 vInputTangent = RsD3DMaterialFromME_fNormalMod * D3_vInputTangent;
float3x3 mToTangent;
// mToTangent[0] = normalize(vInputTangent);
// mToTangent[2] = normalize(vInputNormal);
mToTangent[0] = vInputTangent;
mToTangent[2] = vInputNormal;
mToTangent[1] = cross(mToTangent[0], mToTangent[2]); //The cross product to compute binormal NxT
Output.D3_mToWorld = mul(mToTangent, D3_mObjectToWorldN);
Output.D3_cVertexColor = D3_cInputColor;
rsxi_VarShaderInput;
//------------------------------
//Perform default processing on variables
tsxi_SetInputTangentToWorld(Output.D3_mToWorld);
tsxi_SetInputWorldToObject(D3_mWorldToObject);
tsxi_SetInputObjectToWorld(D3_mObjectToWorld);
tsxi_SetInputTexCoords1(Output.D3_vVertexTexCoords.xyzw);
tsxi_SetInputTexCoords2(Output.D3_vVertexTexCoords.wzyx);
tsxi_SetInputTangent(Output.D3_mToWorld[0]);
tsxi_SetInputNormal(Output.D3_mToWorld[2]);
tsxi_SetInputColor(Output.D3_cVertexColor);
tsxi_SetInputPosition(Output.D3_pVertexPosition);
tsxi_SetInputEyePos(D3_pEye);
tsxi_SetInputEyeDir(Output.D3_vEye.xyz);
tsxi_SetInputEyeDist(Output.D3_vEye.w);
tsxi_SetInputLightDir(Output.D3_vEye.xyz);
tsxi_SetInputLightDist(Output.D3_vEye.w);
tsxi_SetInputLightColor(RtFloat4(1,1,1,1));
#ifdef RsVertexLightShaderName
RtFloat4 vTmpLightColor = tsxi_GetInputLightColor;
RtFloat3 vTmpLightDir = tsxi_GetInputLightDir;
RtFloat vTmpLightDist = tsxi_GetInputLightDist;
RsVertexLightShaderName(rsxi_SendShaderInput, vTmpLightColor, vTmpLightDir, vTmpLightDist);
tsxi_SetInputLightColor(vTmpLightColor);
tsxi_SetInputLightDir(normalize(vTmpLightDir));
tsxi_SetInputLightDist(vTmpLightDist);
#endif
Output.D3_vLightVector.xyz = tsxi_GetInputLightDir;
Output.D3_vLightVector.w = tsxi_GetInputLightDist;
Output.D3_cLightColor = tsxi_GetInputLightColor;
return Output;
}
D3_PIXELOUTPUT RsD3DMaterialFromME_PixelShader(in D3_PIXELINPUT Input)
{
D3_PIXELOUTPUT Output;
rsxi_VarShaderInput;
//------------------------------
//Perform default processing on variables
tsxi_SetInputTangentToWorld(Input.D3_mToWorld);
tsxi_SetInputWorldToObject(D3_mWorldToObject);
tsxi_SetInputObjectToWorld(D3_mObjectToWorld);
tsxi_SetInputTexCoords1(Input.D3_vVertexTexCoords.xyzw);
tsxi_SetInputTexCoords2(Input.D3_vVertexTexCoords.wzyx);
tsxi_SetInputTangent(Input.D3_mToWorld[0]);
tsxi_SetInputNormal(Input.D3_mToWorld[2]);
tsxi_SetInputColor(Input.D3_cVertexColor);
tsxi_SetInputPosition(Input.D3_pVertexPosition);
tsxi_SetInputEyePos(D3_pEye);
tsxi_SetInputEyeDist(Input.D3_vEye.w);
tsxi_SetInputEyeDir(normalize(Input.D3_vEye.xyz));
tsxi_SetInputLightDist(Input.D3_vLightVector.w);
tsxi_SetInputLightDir(Input.D3_vLightVector.xyz);
tsxi_SetInputLightColor(Input.D3_cLightColor);
#ifdef RsTexcoordShaderName
RtFloat3 vTmpTexCrd = tsxi_GetInputTexCoords1;
RsTexcoordShaderName(rsxi_SendShaderInput, vTmpTexCrd);
tsxi_SetInputTexCoords1(vTmpTexCrd);
#endif
#ifdef RsNormalShaderName
RtFloat3 vTmpNormal = tsxi_GetInputNormal;
RtFloat3 vTmpTangent = tsxi_GetInputTangent;
RsNormalShaderName(rsxi_SendShaderInput, vTmpNormal, vTmpTangent);
tsxi_SetInputNormal(normalize(vTmpNormal));
tsxi_SetInputTangent(normalize(vTmpTangent));
#else
tsxi_SetInputNormal(normalize(tsxi_GetInputNormal));
tsxi_SetInputTangent(normalize(tsxi_GetInputTangent));
#endif
#ifdef RsAlphaShaderName
RtFloat fTmpAlpha = tsxi_GetInputAlpha;
RsAlphaShaderName(rsxi_SendShaderInput, fTmpAlpha);
tsxi_SetInputAlpha(fTmpAlpha);
#endif
#ifdef RsColorShaderName
RtFloat4 vTmpColor = tsxi_GetInputColor;
RsColorShaderName(rsxi_SendShaderInput, vTmpColor);
tsxi_SetInputColor(vTmpColor);
#endif
#ifdef RsLightShaderName
RtFloat4 vTmpLightColor = tsxi_GetInputLightColor;
RtFloat3 vTmpLightDir = tsxi_GetInputLightDir;
RtFloat fTmpLightDist = tsxi_GetInputLightDist;
RsLightShaderName(rsxi_SendShaderInput, vTmpLightColor, vTmpLightDir, fTmpLightDist);
tsxi_SetInputLightColor(vTmpLightColor);
tsxi_SetInputLightDist(fTmpLightDist);
tsxi_SetInputLightDir(normalize(vTmpLightDir));
#else
RtFloat3 vTmpLightDir = tsxi_GetInputLightDir;
tsxi_SetInputLightDir(normalize(vTmpLightDir));
#endif
#ifdef RsAlphaShaderName
tsxi_SetInputAlpha(fTmpAlpha);
#endif
RtFloat4 vTmpOutColor = tsxi_GetInputColor;
#ifdef RsModelShaderName
RsModelShaderName(rsxi_SendShaderInput, vTmpOutColor);
#endif
Output.D3_cOutColor = vTmpOutColor;
return Output;
}
pixelshader RsD3DMaterialFromME_PixelShader_ps_2_0 = compile ME_PS_PROFILE RsD3DMaterialFromME_PixelShader();
vertexshader RsD3DMaterialFromME_VertexShader_vs_2_0 = compile ME_VS_PROFILE RsD3DMaterialFromME_VertexShader();
//------------------------------
// Techniques
// This is automatically generated code
//------------------------------
//
//This is technique for non opaque mode
technique D3_MAIN_TECHNIQUE
<
string Rs_PSVersion = "PS_2_0";
string Rs_TechniqueMode = "firstlight";
>
{
#ifdef RsAlphaShaderName
pass D3_PASS_01
{
VertexShader = (RsD3DMaterialFromME_VertexShader_vs_2_0);
PixelShader = (RsD3DMaterialFromME_PixelShader_ps_2_0);
AlphaBlendEnable = true;
SrcBlend = SRCALPHA;
DestBlend = INVSRCALPHA;
ZEnable = true;
ZFunc = LESSEQUAL;
ZWriteEnable = true;
}
#else
pass D3_PASS_01
{
VertexShader = (RsD3DMaterialFromME_VertexShader_vs_2_0);
PixelShader = (RsD3DMaterialFromME_PixelShader_ps_2_0);
AlphaBlendEnable = false;
ZEnable = true;
ZFunc = LESSEQUAL;
ZWriteEnable = true;
CullMode = CCW;
}
#endif //RsAlphaShaderName
}
technique D3_MAIN_TECHNIQUE_MOREPASSES
<
string Rs_PSVersion = "PS_2_0";
string Rs_TechniqueMode = "morelights";
>
{
#ifdef RsAlphaShaderName
pass D3_PASS_01
{
VertexShader = (RsD3DMaterialFromME_VertexShader_vs_2_0);
PixelShader = (RsD3DMaterialFromME_PixelShader_ps_2_0);
AlphaBlendEnable = true;
SrcBlend = SRCALPHA;
DestBlend = ONE;
ZEnable = true;
ZFunc = EQUAL;
ZWriteEnable = false;
}
#else
pass D3_PASS_01
{
VertexShader = (RsD3DMaterialFromME_VertexShader_vs_2_0);
PixelShader = (RsD3DMaterialFromME_PixelShader_ps_2_0);
AlphaBlendEnable = true;
SrcBlend = ONE;
DestBlend = ONE;
ZEnable = true;
ZFunc = EQUAL;
ZWriteEnable = false;
CullMode = CCW;
}
#endif //RsAlphaShaderName
}